package 疯狂Java讲义.第6章_面向对象_下._6_9_枚举类._6_9_3_枚举类的成员变量和方法和构造器;

public enum betterGender {
    MALE, FEMALE;
    private String name;

    public void setName(String name) {
        switch (this){
            case MALE -> {
                if (name.equals("男")){
                    this.name = name;
                }
                else {
                    System.out.println("参数错误");
                }
            }
            case FEMALE -> {
                if (name.equals("女")){
                    this.name = name;
                }
                else {
                    System.out.println("参数错误");
                }
            }
        }
    }

    public String getName() {
        return name;
    }
}
